package com.example.leetcode.solution;

public class Solution14 {
    public static String longestCommonPrefix(String[] strs) {
        if (strs != null && strs.length > 0) {
            StringBuilder result = new StringBuilder();
            for (int j = 0; j < strs[0].length(); j++) {
                StringBuilder temp = new StringBuilder(result);
                temp.append(strs[0].charAt(j));
                for (int i = 1; i < strs.length; i++) {
                    if (!strs[i].startsWith(temp.toString())) {
                        return result.toString();
                    }
                }
                result = temp;
            }
            return result.toString();
        }
        return "";
    }
}
